package com.example.demo.util;

import com.example.demo.entity.RegisterEntity;
import com.example.demo.service.RegisterService;
import com.example.demo.service.impl.RegisterServiceImpl;
import com.sun.xml.internal.bind.v2.TODO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class FileUtil {

    public static final String  UPLOADS_PAHT = "/root/xpj_images/";
//public static final String  UPLOADS_PAHT = "C:\\Users\\win10\\Desktop\\test\\";
    @Autowired
    private static RegisterServiceImpl registerService;

    public static String uploadImg(MultipartFile file , String serialNumber) throws IOException {

        //获取文件后缀
        final String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.')+1);

        //文件名（id + fileSuffix ）
        String fileName =serialNumber+"."+ fileSuffix;
        //文件写入
        File descFile = new File(UPLOADS_PAHT,fileName);
        //翻译文件
        file.transferTo(descFile);
        String url =fileName;
        return url;
    }
}
